package com.study.component;

import com.study.component2.MyBean1;
import com.study.component2.MyBean2;
import com.study.component2.MyBean3;
import com.study.component2.MyBean4;
import com.study.component2.MyFactoryBean.MyBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @Author tanglingyu
 * @Date: 2021/09/01/ 10:21
 * @Description
 */
@Component
public class MyComcandLineRunner implements CommandLineRunner {

  @Autowired
  private ApplicationContext applicationContext;

  @Autowired
  private MyBean1 myBean1;

  @Autowired
  private MyBean2 myBean2;

  @Autowired
  private MyBean3 myBean3;

  @Autowired
  private MyBean4 myBean4;

  @Override
  public void run(String... args) throws Exception {
    final MyBean bean = applicationContext.getBean("myFactoryBean", MyBean.class);
    System.out.println(bean.getName());
    System.out.println(myBean1.getName());
    System.out.println(myBean2.getName());
    System.out.println(myBean3.getName());
    System.out.println(myBean4.getName());
  }
}
